I'm using a uCompoents Url Picker on my doctype, so within my razor scipt i'd like to check for the existance of a property (actually, its an element) as follows:
@myNode.MyUrlPicker.Url
if "url" doesn't exist then razor will blow up rather than returning null. Is it possible for DynamicXml and DynamicNode to return null when something doesn't exist rather then blowing up?
I found this post, but it still seems a bit verbose to incorporate this code into my project. it really seems like core logic:
That code is mine, it's purpose is to handle Dynamic XML specifically.
I also tought it was a lot of code for such a basic need and that's why I shared it. I'm not sure if nowadays it's still that hard to check if a proprty exists, at that time what we found was that if we changed the uComponent data type to save as CSV it would come in a much easier to handle DynamicNode format. Could that be your case?
I think its just the nature of XML that all these types of checks are required.. My point was to have your code incorporated into the ucomponents codebase rather than having to use it as a separate helper function.
check property/element exists [dynamicXml]
I'm using a uCompoents Url Picker on my doctype, so within my razor scipt i'd like to check for the existance of a property (actually, its an element) as follows:
@myNode.MyUrlPicker.Url
if "url" doesn't exist then razor will blow up rather than returning null. Is it possible for DynamicXml and DynamicNode to return null when something doesn't exist rather then blowing up?
I found this post, but it still seems a bit verbose to incorporate this code into my project. it really seems like core logic:
http://whatis.goingle.me/dynamicxml-propertyhasvalue-implementation-um
thanks!
Think that the following should work. You can build in an extra string.IsNullOrEmpty for the url if you want to.
if(myNode.HasValue("MyUrlPicker"))
{
}
i don't think that works but will re-try.
HasProperty, HasValue and IsNull where the first things i tried from the cheatsheet.
Hi Andrew,
That code is mine, it's purpose is to handle Dynamic XML specifically.
I also tought it was a lot of code for such a basic need and that's why I shared it. I'm not sure if nowadays it's still that hard to check if a proprty exists, at that time what we found was that if we changed the uComponent data type to save as CSV it would come in a much easier to handle DynamicNode format. Could that be your case?
Best regards,
JRA
I think its just the nature of XML that all these types of checks are required.. My point was to have your code incorporated into the ucomponents codebase rather than having to use it as a separate helper function.
is working on a reply...